webix.ready(function(){
  var params={};
  var my_template={
    template: "<span style='font-size:20px; font-weight:bold; color:#3498DB'; >库存状况</span>&nbsp;/&nbsp;&nbsp;" +
    		"CutterUse &nbsp;<select id='isAll'><option value='0'>全部</option><option value='1'>当前库存大于0</option></select>&nbsp;" +
    		"<input type='button' value=' 查 询 ' onclick='sub();' style='background: #268fd5;background: 1px solid #268fd5;color: #fff;'>&nbsp;" +
    		"<input type='button' value=' 导 出 ' onclick='exportExcel();' style='background: #268fd5;background: 1px solid #268fd5;color: #fff;'>",
    height:45,
    borderless:true 
  };
  var my_datatable={
    view:"datatable",
    id:"mydatatable",   
    columns:[
      {id:"material_id",header:["内部物料编码"],fillspace:true,hidden:true},
      {id:"cutter_specs",hidden:true,header:["规格",{content:"textFilter",placeholder:"请输入规格名称查询"}],fillspace:true},
      {id:"customer_specs_no",header:["物料编码"],fillspace:true},
      {id:"simple_specs_cust",header:["规格简称",{content:"textFilter",placeholder:"请输入规格名称查询"}],fillspace:true},
      {id:"long_specs_cust",header:["规格全称",{content:"textFilter",placeholder:"请输入规格名称查询"}],fillspace:true},

      {id:"supp_name",header:"供应商",fillspace:true},
      {id:"now_num",header:"当前库存",fillspace:true},
      {id:"safe_num",header:"安全库存",fillspace:true},
      {id:"use_num",header:"领用数量",fillspace:true},
      {id:"rec_num",header:"回收数量",fillspace:true},
      {id:"date",header:"统计日期",fillspace:true},
      {id:"cz",header:"操作",template:"<a class='btn1' href='javascript:void(0);' onclick=\"details('#material_id#')\">查看详情</a>",width:100},    
    ],     
    tooltip:true,
    height:700,      
    select:true,
    editable:true,
    checkboxRefresh:true,
    // url:"http://192.168.1.111:9001/Application/demo"
    // url:""
  };
  var page={
    view:"pager",
    id:"pagerA",
	//新用户刚开始没有产生数据出现分页标签
   // count:1000,
    //master:false,
    //group:15,
    //size:5,
    //page:1,
    template:"{common.first()}{common.prev()}{common.pages()}{common.next()}{common.last()}",
    css:"pager",
    on: {
      onItemClick: function(id, e, node){
        if (id == "next") {
          if($$("pagerA").config.limit==$$("pagerA").config.page+1)
            {
              id = $$("pagerA").config.limit-1;
            }
          else
          {
            id=$$("pagerA").config.page+1;
          }
        }
        else if(id=="prev")
        {
          id=$$("pagerA").config.page-1; 
        }
        else if(id=="first")
        {
          id=0;
        }
        else if(id=="last")
        {
          id=$$("pagerA").config.limit-1;
        } 
        var params={};
        var isAll = $('#isAll').val();
        params.currPage =parseInt(id)+1;
        params.pageSize =20;
        params.isAll = isAll;
        postData("getInventoryAllList", params,callback);
      }
    },
    height:38,
    css:{"text-align": "center","margin-top":"20px!important"}
  };
  var params={};
  params.isAll = "0";
  params.pageSize =20;
  postData("getInventoryAllList", params,callback);
  var web={
    container:"body",
    type:"line",
    id:"mylayout",
    rows:[
      my_template,
      {height:10},
      my_datatable,
      page
    ],
  };
  webix.ui(web);//---webix.ui结束----
})

function sub(){
	var initDate = [{"material_id":"加载中..."}]
	$$("mydatatable").clearAll();
	$$("mydatatable").define("data",initDate);
	$$('mydatatable').refresh();
	var isAll = $('#isAll').val();
	var params={};
	params.pageSize = 20;
	params.isAll = isAll;
	postData("getInventoryAllList", params,callback);
}
function callback(data){
  result =JSON.parse(data);
  text1=result.data; 
  var conditions = text1.conditions;
  if(conditions.hasOwnProperty("date")){
	  $("#date").val(conditions.start_date); 
  }
  //var data = new webix.DataCollection({data:text1.page});
    // $$('mydatatable').data.sync(data);
  $$("mydatatable").clearAll();
  $$("mydatatable").define("data",text1.page);
  console.log(JSON.stringify(text1.page));
  $$('mydatatable').refresh();
  $$("pagerA").define("limit",text1.totalPageCount);
  $$("pagerA").define("count",text1.totalCount);
  $$("pagerA").define("size",text1.pageSize);
  $$("pagerA").define("page",text1.currPage-1);
  $$('pagerA').refresh();
}
function details(mid){
	  location.href="cutterUseIndex?material_id="+mid+"&date="+$("#date").val();
}
